//
//  HLtcViewController.m
//  Router
//
//  Created by Zhen Huang on 2018/6/26.
//  Copyright © 2018年 James. All rights reserved.
//

#import "HLtcViewController.h"
#import "HLtcModel.h"
#import "HLtcTableViewCell.h"
#import "ZBDownMenuView.h"
#import <Masonry/Masonry.h>
typedef NS_ENUM(NSInteger, RefreshDataType) {
    RefreshDataTypeHeader,
    RefreshDataTypeFooter,
};

@interface HLtcViewController ()
<UITableViewDelegate,
UITableViewDataSource>
@property (nonatomic, strong) UITableView *tabelview;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, assign) NSInteger page_Num;
@property (nonatomic, assign) RefreshDataType orderType;
@property (nonatomic, strong) ZBDownMenuView *downMenuView;
@property (nonatomic, strong) NSMutableArray *dataListArray;
@property (nonatomic, strong) NSMutableArray *allDataArray;
@property (nonatomic, strong) NSMutableArray *chooseArray;
@property (nonatomic, strong) UIView *lctView;
@property (nonatomic, assign) BOOL isEditing;
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) UIView *bgView;//半透明背景
@property (nonatomic, strong) UIView *alertView;//假设为弹窗
@property (nonatomic, strong) UIView *editingView;

@end
@implementation HLtcViewController
- (instancetype)init {
    if (self) {
        self.chooseArray = [NSMutableArray new];
        self.dataArray = [NSMutableArray new];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kBackGroundColor;
    self.page_Num = 1;
    [self requestNetWorkingWith:(RefreshDataTypeHeader)ordering:-1 is_mount:-1 is_online:-1 yesterday:-1];
    [self conflictingDownMenuView];
    __weak typeof(HLtcViewController *) weakSelf = self;
    self.tabelview.mj_header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
        [weakSelf.tabelview.mj_header endRefreshing];
        [weakSelf.tabelview.mj_footer endRefreshing];
        if (self.dataArray.count > 0) {
            [self requestNetWorkingWith:(RefreshDataTypeHeader)ordering:-1 is_mount:-1 is_online:-1 yesterday:-1];
        }
    }];
    self.tabelview.mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        [weakSelf.tabelview.mj_header endRefreshing];
        [weakSelf.tabelview.mj_footer endRefreshing];
        if (self.dataArray.count > 0) {
            [weakSelf requestNetWorkingWith:(RefreshDataTypeFooter)ordering:-1 is_mount:-1 is_online:-1 yesterday:-1];
        }
    }];
    [self Adds];
}

/* 配置DownMenuView */
- (void)conflictingDownMenuView {
    _downMenuView = [[ZBDownMenuView alloc]initWithFrame:CGRectMake(0, NavBarHeight , ScreenWidth, 40)];
    _downMenuView.titleArray = [NSArray arrayWithObjects:@"综合",@"产量(默认)", nil];
    _downMenuView.dataSourceArr = @[@[@"综合", @"掉盘", @"离线", @"零产量"],
                                    @[@"产量(默认)", @"升序", @"降序"]].mutableCopy;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(_downMenuView.frame.size.width / 3 * 2, 10, 100, 20);
    [_downMenuView addSubview:button];
    button.contentHorizontalAlignment = 2;
    [button setTitleColor:kTitleBackGroundColor forState:UIControlStateNormal];
    [button setTitle:@"批量处理" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont fontWithName:PingFangSCRegular size:15];
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
        if (!self.editing) {
            [button setTitle:@"取消处理" forState:UIControlStateNormal];
            [self.tabelview setEditing:YES animated:YES];
        }else{
            [self.chooseArray removeAllObjects];
            [self.tabelview setEditing:NO animated:YES];
            [self showEitingView:NO];
            [button setTitle:@"批量处理" forState:UIControlStateNormal];
        }
        self.isEditing = !self.isEditing;
    }];

    [self.view addSubview:_downMenuView];
    _downMenuView.conditionBlock = ^(NSString *currentTitle, NSArray *currentTitleArray ,NSInteger row){
        int ordering = -1;
        int is_mount = -1;
        int is_online = -1;
        int yesterday = -1;

        if ([currentTitleArray containsObject:@"综合"]) {
            is_mount = -1;
            is_online = -1;
            yesterday = -1;
        }
        if ([currentTitleArray containsObject:@"掉盘"]) {
            is_mount = 0;
            is_online  = -1;
            yesterday = -1;
        }
        if ([currentTitleArray containsObject:@"离线"]) {
            is_mount = -1;
            is_online = 0;
            yesterday = -1;
        }
        if ([currentTitleArray containsObject:@"零产量"]) {
            is_mount = -1;
            is_online = -1;
            yesterday = 0;
        }
        if ([currentTitleArray containsObject:@"产量(默认)"]) {
            ordering = -1;
        }
        if ([currentTitleArray containsObject:@"升序"]) {
            ordering = 0;
        }
        if ([currentTitleArray containsObject:@"降序"]) {
            ordering = 1;
        }
        [self requestNetWorkingWith:RefreshDataTypeHeader ordering:ordering is_mount:is_mount is_online:is_online yesterday:yesterday];
    };
}
- (UITableView *)tabelview {
    if (!_tabelview) {
        _tabelview = [[UITableView alloc]initWithFrame:CGRectMake(0, self.downMenuView.bottom, ScreenWidth, ScreenHeight - NavBarHeight) style:UITableViewStylePlain];
        _tabelview.delegate = self;
        _tabelview.dataSource = self;
        _tabelview.backgroundColor = kBackGroundColor;
        _tabelview.separatorColor = [UIColor colorWithCGColor:[kStrokeBackGroundColor CGColor]];
        [_tabelview registerClass:[HLtcTableViewCell class] forCellReuseIdentifier:@"CellID"];
        _tabelview.tableFooterView = [[UIView alloc]init];
        _tabelview.allowsMultipleSelectionDuringEditing = YES;
    }
    return _tabelview;
}

- (void)Adds{
    [self.view addSubview:self.tabelview];
    [self.view addSubview:self.editingView];
    [self.tabelview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.downMenuView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.editingView.mas_top);
    }];
    
    [self.editingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.equalTo(@(45 + 49));
        make.bottom.equalTo(self.view).offset(45 + 49 + self.downMenuView.height);
    }];
}

- (void)showEitingView:(BOOL)isShow{
    [self.editingView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(isShow?0:45);
    }];
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HLtcTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellID" forIndexPath:indexPath];
    cell.backgroundColor = kBackGroundColor;
    HLtcModel *model = self.dataArray[indexPath.row];
    cell.tempModel = model;
    cell.preservesSuperviewLayoutMargins = NO;
    cell.separatorInset = UIEdgeInsetsZero;
    cell.layoutMargins = UIEdgeInsetsZero;
    cell.selectedBackgroundView = [[UIView alloc]init];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

- (void)requestNetWorkingWith:(RefreshDataType)type ordering:(int)ordering is_mount:(int)is_mount is_online:(int)is_online yesterday:(int)yesterday{
    
    self.orderType = type;
    if (type == RefreshDataTypeHeader) {
        self.page_Num = 1;
    }else {
        self.page_Num++;
    }
    NSString *url = F(@"%@/routers?page_size=10&page_num=%ld", BaseUrl,self.page_Num);
    if (ordering != -1) {
        if (ordering == 0) {
            url = [url stringByAppendingString:[NSString stringWithFormat:@"&ordering=%@",@"yesterday_output"]];
        }else {
            url = [url stringByAppendingString:[NSString stringWithFormat:@"&ordering=%@",@"-yesterday_output"]];
        }
    }
    if (is_mount != -1) {
        url = [url stringByAppendingString:[NSString stringWithFormat:@"&is_mount=%d",0]];
    }
    if (is_online != -1) {
        url = [url stringByAppendingString:[NSString stringWithFormat:@"&is_online=%d",is_online]];
    }
    if (yesterday != -1) {
        url = [url stringByAppendingString:[NSString stringWithFormat:@"&yesterday_output=%d",0]];
    }
    NSString *Token = F(@"Token %@",  [[TMCache sharedCache] objectForKey:@"Token"]);
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [self receivePOSTWithTokenURLString:url method:@"GET" body:nil Token:Token Blocks:^(NSDictionary *tempData, NSInteger state) {
            if (tempData) {
                if (type == RefreshDataTypeHeader) {
                    [self.dataArray removeAllObjects];
                }
                NSArray *resultsArray = [tempData valueForKey:@"results"];
                   NSArray *array = [HLtcModel mj_objectArrayWithKeyValuesArray:[tempData valueForKey:@"results"]];
                    [self.dataArray addObjectsFromArray:array];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.view addSubview:self.tabelview];
                    if (self.dataArray.count == 0) {
                        [self nothingView];
                    }else {
                        [self.view addSubview:self.tabelview];
                    }
                    if (resultsArray.count < 10) {
                        [self.tabelview.mj_footer endRefreshingWithNoMoreData];
                    }else {
                        [self.tabelview.mj_footer resetNoMoreData];
                    }
                    [self.tabelview reloadData];
                });
            }
        }];
    });
}
- (void)nothingView {
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, NavBarHeight + 10, ScreenWidth - 20, 200)];
    image.image = [UIImage imageNamed:@"Luyou"];
    image.contentMode = UIViewContentModeScaleAspectFit;
    image.center = self.view.center;
    [self.view addSubview:image];
}

- (UIView *)editingView{
    if (!_editingView) {
        _editingView = [[UIView alloc] init];
        _editingView.backgroundColor = kWidgetBackGroundColor;
        UIButton *chongqiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        chongqiBtn.frame = CGRectMake(ScreenWidth / 4, 10, ScreenWidth / 4 - 10, 25);
        chongqiBtn.layer.masksToBounds = YES;
        chongqiBtn.layer.cornerRadius = 10;
        chongqiBtn.backgroundColor = kNavBlueColor;
        [chongqiBtn setTitle:@"重启矿机" forState:UIControlStateNormal];
        [chongqiBtn addTarget:self action:@selector(chongqi:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *qingchuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        qingchuBtn.frame = CGRectMake(chongqiBtn.right + 5, 10, ScreenWidth / 4  - 10, 25);
        qingchuBtn.layer.masksToBounds = YES;
        qingchuBtn.layer.cornerRadius = 10;
        qingchuBtn.backgroundColor = RGB(59, 191, 163);
        [qingchuBtn setTitle:@"清除缓存" forState:UIControlStateNormal];
        [qingchuBtn addTarget:self action:@selector(qingchu:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        deleteBtn.frame = CGRectMake(qingchuBtn.right + 5, 10, ScreenWidth / 4 - 10, 25);
        deleteBtn.layer.masksToBounds = YES;
        deleteBtn.layer.cornerRadius = 10;
        deleteBtn.backgroundColor = RGB(245, 80, 107);
        [deleteBtn setTitle:@"删除设备" forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
        
        [_editingView addSubview:chongqiBtn];
        [_editingView addSubview:qingchuBtn];
        [_editingView addSubview:deleteBtn];

    }
    return _editingView;
}

- (void)chongqi:(UIButton *)sender {
    
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示"
                                                                   message:@"是否选择重启矿机?"
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              NSString *url = F(@"%@/routers/commands", BaseUrl);
                                                              NSString *Token = F(@"Token %@",  [[TMCache sharedCache] objectForKey:@"Token"]);
                                                              NSMutableArray *array = [NSMutableArray new];
                                                              for (int i = 0 ; i < self.chooseArray.count; i ++ ) {
                                                                  HLtcModel *model = self.chooseArray[i];
                                                                  [array addObject:model.uuid];
                                                              }
                                                              NSDictionary *paramDic = @{@"uuid_list":array,
                                                                                         @"command":@1};
                                                              NSString *param = [self dictionaryToJson:paramDic];
                                                              dispatch_async(dispatch_get_global_queue(0, 0), ^{
                                                                  [self receivePOSTWithTokenURLString:url method:@"POST" body:param Token:Token Blocks:^(NSDictionary *tempData, NSInteger state) {
                                                                      if (tempData) {
                                                                          [self.chooseArray removeAllObjects];
                                                                          dispatch_async(dispatch_get_main_queue(), ^{
                                                                              [self.tabelview setEditing:NO animated:YES];
                                                                              [HCommon popupSuccessMessage:@"操作成功"];
                                                                              [self showEitingView:NO];
                                                                              self.editing = !self.editing;
//                                                                              [self.tabelview reloadData];
                                                                          });
                                                                      }
                                                                  }];
                                                              });
                                                          }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                         }];
    [alert addAction:cancelAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)qingchu:(UIButton *)sender {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示"
                                                                   message:@"是否选择清除缓存?"
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              NSString *url = F(@"%@/routers/commands", BaseUrl);
                                                              NSString *Token = F(@"Token %@",  [[TMCache sharedCache] objectForKey:@"Token"]);
                                                              NSMutableArray *array = [NSMutableArray new];
                                                              for (int i = 0 ; i < self.chooseArray.count; i ++ ) {
                                                                  HLtcModel *model = self.chooseArray[i];
                                                                  [array addObject:model.uuid];
                                                              }
                                                              NSDictionary *paramDic = @{@"uuid_list":array,
                                                                                         @"command":@2};
                                                              NSString *param = [self dictionaryToJson:paramDic];
                                                              dispatch_async(dispatch_get_global_queue(0, 0), ^{
                                                                  [self receivePOSTWithTokenURLString:url method:@"POST" body:param Token:Token Blocks:^(NSDictionary *tempData, NSInteger state) {
                                                                      if (tempData) {
                                                                          [self.chooseArray removeAllObjects];
                                                                          dispatch_async(dispatch_get_main_queue(), ^{
                                                                              [HCommon popupSuccessMessage:@"操作成功"];
                                                                              [self.tabelview setEditing:NO animated:YES];
                                                                              [self showEitingView:NO];
                                                                              self.editing = NO;
                                                                              [self.tabelview reloadData];
                                                                          });
                                                                      }
                                                                  }];
                                                              });
                                                          }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                         }];
    [alert addAction:cancelAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)delete:(UIButton *)sender {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示"
                                                                   message:@"是否选择删除设备?"
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              NSString *url = F(@"%@/routers/commands", BaseUrl);
                                                              NSString *Token = F(@"Token %@",  [[TMCache sharedCache] objectForKey:@"Token"]);
                                                              NSMutableArray *array = [NSMutableArray new];
                                                              for (int i = 0 ; i < self.chooseArray.count; i ++ ) {
                                                                  HLtcModel *model = self.chooseArray[i];
                                                                  [array addObject:model.uuid];
                                                              }
                                                              NSDictionary *paramDic = @{@"uuid_list":array,
                                                                                         @"command":@4};
                                                              NSString *param = [self dictionaryToJson:paramDic];
                                                              dispatch_async(dispatch_get_global_queue(0, 0), ^{
                                                                  [self receivePOSTWithTokenURLString:url method:@"POST" body:param Token:Token Blocks:^(NSDictionary *tempData, NSInteger state) {
                                                                      if (tempData) {
                                                                          [self.chooseArray removeAllObjects];
                                                                          dispatch_async(dispatch_get_main_queue(), ^{
                                                                              [HCommon popupSuccessMessage:@"操作成功"];
                                                                              [self.tabelview setEditing:NO animated:YES];
                                                                              [self showEitingView:NO];
                                                                              self.editing = NO;
                                                                              [self.tabelview reloadData];
                                                                          });
                                                                      }
                                                                  }];
                                                              });
                                                          }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                         }];
    [alert addAction:cancelAction];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *subviews = [[tableView cellForRowAtIndexPath:indexPath] subviews];
    for (id obj in subviews) {
        if ([obj isKindOfClass:[UIControl class]]) {
            for (id subview in [obj subviews]) {
                if ([subview isKindOfClass:[UIImageView class]]) {
                    [subview setValue:kNavBlueColor forKey:@"tintColor"];
                    break;
                }
            }
        }
    }
    HLtcModel *model = [self.dataArray objectAtIndex:indexPath.row];
    if (self.editing) {
        [self.chooseArray addObject:model];
        if (self.chooseArray == 0) {
            [self showEitingView:NO];
        }else {
            [self showEitingView:YES];
        }
    }else {
        [self showRouterWithHltcModel:model];
    }
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.editing) {
        HLtcModel *newModel = [self.dataArray objectAtIndex:indexPath.row];
        [self.chooseArray removeObject:newModel];
        if (self.chooseArray.count == 0) {
            [self showEitingView:NO];
        }else {
            [self showEitingView:YES];
        }
    }
}
- (void)showRouterWithHltcModel:(HLtcModel *)model {
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    _bgView = [[UIView alloc]init];
    _bgView.frame = window.bounds;
    _bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
    _bgView.layer.masksToBounds = YES;
    _bgView.layer.cornerRadius = 5;
    [window addSubview:_bgView];
    _alertView = [[UIView alloc ]initWithFrame:CGRectMake(10, ScreenWidth / 2, ScreenWidth - 20, 230)];
    _alertView.backgroundColor = kBackGroundColor;
    
    UILabel *detailLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5,_alertView.width, 30)];
    detailLabel.text = @"详情";
    detailLabel.font = [UIFont fontWithName:PingFangSCRegular size:16];
    detailLabel.textColor = kTitleBackGroundColor;
    detailLabel.textAlignment = 1;
    
    UILabel *userNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 40, _alertView.width / 2, 20)];
    userNumberLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    userNumberLabel.textAlignment = 0;
    userNumberLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *wifiLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, 40, _alertView.width / 2 - 10, 20)];
    wifiLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    wifiLabel.textAlignment = 0;
    wifiLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *yesterdayLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, userNumberLabel.bottom + 10, ScreenWidth / 2, 20)];
    yesterdayLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    yesterdayLabel.textAlignment = 0;
    yesterdayLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *upLoadLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, userNumberLabel.bottom + 10, _alertView.width / 2 -10 , 20)];
    upLoadLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    upLoadLabel.textAlignment = 0;
    upLoadLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];

    UILabel *disSizeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, yesterdayLabel.bottom + 10, _alertView.width / 2, 20)];
    disSizeLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    disSizeLabel.textAlignment = 0;
    disSizeLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];

    UILabel *downLoadLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, yesterdayLabel.bottom + 10, _alertView.width / 2 - 10, 20)];
    downLoadLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    downLoadLabel.textAlignment = 0;
    downLoadLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *disUsedLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, disSizeLabel.bottom + 10, _alertView.width / 2, 20)];
    disUsedLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    disUsedLabel.textAlignment = 0;
    disUsedLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *wanIPLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, disSizeLabel.bottom + 10,_alertView.width / 2 - 10, 20)];
    wanIPLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    wanIPLabel.textAlignment = 0;
    wanIPLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *LanIPLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, disUsedLabel.bottom + 10, _alertView.width / 2, 20)];
    LanIPLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    LanIPLabel.textAlignment = 0;
    LanIPLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *publicLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, disUsedLabel.bottom + 10, _alertView.width / 2 - 10, 20)];
    publicLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    publicLabel.textAlignment = 0;
    publicLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *MACLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, LanIPLabel.bottom + 10, _alertView.width / 2, 20)];
    MACLabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    MACLabel.textAlignment = 0;
    MACLabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    UILabel *Timelabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2, LanIPLabel.bottom + 10, _alertView.width / 2 - 10, 20)];
    Timelabel.font = [UIFont fontWithName:PingFangSCRegular size:14];
    Timelabel.textAlignment = 0;
    Timelabel.textColor = [Networking colorWithHexString:@"#C3E5FF"];
    
    userNumberLabel.text = [NSString stringWithFormat:@"账号：%@",model.account?:@""];
    wifiLabel.text = [NSString stringWithFormat:@"WIFI：%@",model.wifi_name?:@""];
    yesterdayLabel.text = [NSString stringWithFormat:@"昨日产量：%.2f",model.yesterday_output];
    upLoadLabel.text = [NSString stringWithFormat:@"上传速率：%@",model.upload_rate?:@""];
    disSizeLabel.text = [NSString stringWithFormat:@"磁盘总量：%@",model.disk_size?:@"" ];
    downLoadLabel.text = [NSString stringWithFormat:@"下载速率：%@",model.download_rate?:@""];
    disUsedLabel.text = [NSString stringWithFormat:@"磁盘使用量：%@",model.disk_used?:@""];
    wanIPLabel.text = [NSString stringWithFormat:@"WAN接口IP：%@",model.wan_ip?:@""];
    LanIPLabel.text = [NSString stringWithFormat:@"LAN接口IP：%@",model.wan_ip?:@""];
    publicLabel.text = [NSString stringWithFormat:@"公网IP：%@",model.public_ip?:@""];
    MACLabel.text = [NSString stringWithFormat:@"MAC：%@",model.mac?:@""];
    Timelabel.text = [NSString stringWithFormat:@"更新时间：%@",model.update_time?:@""];

    [_alertView addSubview:detailLabel];
    [_alertView addSubview:userNumberLabel];
    [_alertView addSubview:wifiLabel];
    [_alertView addSubview:yesterdayLabel];
    [_alertView addSubview:upLoadLabel];
    [_alertView addSubview:disSizeLabel];
    [_alertView addSubview:downLoadLabel];
    [_alertView addSubview:disUsedLabel];
    [_alertView addSubview:wanIPLabel];
    [_alertView addSubview:LanIPLabel];
    [_alertView addSubview:publicLabel];
    [_alertView addSubview:MACLabel];
    [_alertView addSubview:Timelabel];

    [window addSubview:_alertView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideAlertView)];
    [_bgView addGestureRecognizer:tap];
}
- (void)hideAlertView{
    [self performSelector:@selector(remove) withObject:nil afterDelay:0.3];
    _alertView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, 49);
}
- (void)remove{
    [_bgView removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
